
const fullMenus = [{
    title: 'Dashboard',
    key: 'Home',
    icon: 'icon-monitor',
    count: 1
}, {
    title: 'Icons',
    key: 'Icons',
    icon: 'h-icon-home'
}, {
    title: '列表应用',
    key: 'tablelist',
    icon: 'h-icon-home',
    children: [{
        title: '表单页面',
        key: 'TableBasic',
        href: "/views/form.html",
        target: "pages_iframe",
        nativeLink: true
    }, {
        title: '查询列表',
        key: 'TableSearch',
        href: "/views/home.html",
        target: "pages_iframe",
        nativeLink: true
    }]
}, {
    title: '表单应用',
    key: 'form-folder',
    icon: 'h-icon-home',
    children: [{
        title: '基础表单',
        key: 'Form'
    }, {
        title: '表单详情',
        key: 'FormDetail'
    }]
}, {
    title: '模糊匹配',
    key: 'AutoComplete-folder',
    icon: 'h-icon-home',
    children: [{
        title: '模糊搜索',
        key: 'Autocomplete1'
    }, {
        title: '场景应用',
        key: 'Autocomplete2'
    }, {
        title: '复杂场景',
        key: 'Autocomplete3'
    }]
}, {
    title: '扩展组件',
    key: 'Advance-folder',
    icon: 'h-icon-home',
    children: [{
        title: '图表',
        key: 'Chart'
    }, {
        title: '富文本编辑器',
        key: 'RicktextEditor'
    }, {
        title: '代码编辑器',
        key: 'CodeEditor'
    }, {
        title: 'Markdown编辑器',
        key: 'MarkdownEditor'
    }, {
        title: '百度地图',
        key: 'BaiduMap'
    }]
}, {
    title: '系统设置',
    key: 'SysSetting',
    icon: 'h-icon-home',
    children: [{
        title: '个人中心',
        key: 'AccountBasic'
    }, {
        title: '安全设置',
        key: 'SecuritySetting'
    }, {
        title: '权限设置',
        key: 'Authorization',
        href: "/views/sys/permissionList.html",
        target: "pages_iframe",
        nativeLink: true
    }
    ]
}, {
    title: '运维管理',
    key: 'SysSetting1',
    icon: 'h-icon-home',
    children: [{
        title: '个人中心',
        key: 'AccountBasic1'
    }, {
        title: '运维管理2',
        key: 'SysSetting12',
        children: [{
            title: '个人中心',
            key: 'AccountBasic2'
        }, {
            title: '安全设置',
            key: 'SecuritySetting2'
        }, {
            title: '权限设置',
            icon: 'h-icon-home',
            key: 'Authorization2',
            href: "/views/sys/permissionList.html",
            target: "pages_iframe",
            nativeLink: true
        },
        ]
    }
    ]
}];


function arrayToTree(list, parId) {
    let len = list.length

    function loop(parId) {
        let res = [];
        for (let i = 0; i < len; i++) {
            let item = list[i];
            if (item.ParentId === parId) {
                var temp = {
                    title: item.Name,
                    icon: item.Icon,
                    key: item.ID,
                    href: item.Url,
                    target: "pages_iframe",
                    nativeLink: true
                }
                var _children = loop(item.ID);
                if (_children.length > 0) {
                    temp.children = _children;
                }
                res.push(temp)
            }
        }
        return res
    }
    return loop(parId)
}

new Vue({
    el: "#app",
    data: {
        value: "",
        searchText: '',
        siderCollapsed: false,
        infoMenu: [{
            key: 'info',
            title: '个人信息',
            icon: 'h-icon-user'
        }, {
            key: 'logout',
            title: '退出登录',
            icon: 'h-icon-outbox'
        }],
        User: {
            name: "系统管理员",
            avatar: "http://5b0988e595225.cdn.sohucs.com/images/20181222/6064179813734aeaa1e1e0840bddf4b4.jpeg"
        },
        menus: fullMenus
    },
    methods: {
        showSettingModal: function () {

        },
        trigger: function () {

        },
        hideMenu: function () {

        },
        onSiderMenu: function () {
            this.siderCollapsed = this.siderCollapsed ? false : true;
        },
        loadMenuData() {
            var _this=this;
            $http.post("SysMenu/listData", {}, function (d) {
                var newd = arrayToTree(d, 0);
                _this.menus=newd;
            })
        }
    },
    computed: {
        siderCollapsed: function () {
            return this.siderCollapsed;
        }
    },
    mounted() {
        this.loadMenuData();
    },
})
